<?php
// +----------------------------------------------------------------------
// | Bwsaas
// +----------------------------------------------------------------------
// | Copyright (c) 2015~2020 http://www.buwangyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Gitee ( https://gitee.com/buwangyun/bwsaas )
// +----------------------------------------------------------------------
// | Author: buwangyun <hnlg666@163.com>
// +----------------------------------------------------------------------
// | Date: 2020-9-28 10:55:00
// +----------------------------------------------------------------------

namespace app\common\model;

use buwang\base\BaseModel;
use think\facade\Env;

class MemberPayment extends BaseModel
{

    protected $pk = 'id';

    /**
     * 获取配置参数
     * @param array 数据
     * @return bool
     */
    public static function config(int $miniapp_id, string $apiname)
    {
        $rel = self::field('config')->where(['member_miniapp_id' => $miniapp_id, 'apiname' => $apiname])->find();
        if (empty($rel) || !$rel) {
            return false;
        }
        $config = json_decode($rel['config'], true);
        $config['cert_path'] = empty($config['cert_path']) ? '' : Env::get('runtime_path') . 'cert' . DS . $miniapp_id . DS . $config['cert_path'];
        $config['key_path'] = empty($config['key_path']) ? '' : Env::get('runtime_path') . 'cert' . DS . $miniapp_id . DS . $config['key_path'];
        return $config;
    }
}